package com._51cto.healthy.service;

import com._51cto.healthy.mapper.ReportMapper;
import com._51cto.healthy.utils.DateUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@DubboService
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMapper reportMapper;

    /**
     reportDate:null,
     todayNewMember :0,
     totalMember :0,
     thisWeekNewMember :0,
     thisMonthNewMember :0,
     todayOrderNumber :0,
     todayVisitsNumber :0,
     thisWeekOrderNumber :0,
     thisWeekVisitsNumber :0,
     thisMonthOrderNumber :0,
     thisMonthVisitsNumber :0,
     hotSetmeal :[
     {name:'体检套餐',setmeal_count:200,proportion:0.222},
     {name:'体检套餐',setmeal_count:200,proportion:0.222}
     ]
     */
    //    查询运营数据
    @Override
    public Map<String, Object> getBusinessReport() throws Exception {

        //获取当前时间并且转换成字符串
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //动态获得本周一的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //动态获得本月第一天的日期
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());

        //今日新增会员数
        Integer todayNewMember = reportMapper.findMemberCountByDate(today);
        //总会员数据
        Integer totalMember = reportMapper.findMemberTotalCount();
        //本周新增会员数
        Integer thisWeekNewMember = reportMapper.findMemberCountAfterDate(thisWeekMonday);
        //本月新增会员数,同样的方法传入的参数不同
        Integer thisMonthNewMember = reportMapper.findMemberCountAfterDate(firstDay4ThisMonth);

        //今日预约数
        Integer todayOrderNumber = reportMapper.findOrderCountByDate(today);

        //本周预约数
        Integer thisWeekOrderNumber = reportMapper.findOrderCountAfterDate(thisWeekMonday);

        //本月预约数
        Integer thisMonthOrderNumber = reportMapper.findOrderCountAfterDate(firstDay4ThisMonth);

        //今日到诊数
        Integer todayVisitsNumber = reportMapper.findVisitsCountByDate(today);

        //本周到诊数
        Integer thisWeekVisitsNumber = reportMapper.findVisitsCountAfterDate(thisWeekMonday);

        //本月到诊数
        Integer thisMonthVisitsNumber = reportMapper.findVisitsCountAfterDate(firstDay4ThisMonth);

        //热门套餐,获取前四个套餐
        List<Map> hotSetmeal = reportMapper.findHotSetmeal();
//        ==================================
        HashMap<String, Object> map = new HashMap<>();
        map.put("reportDate", today);
        map.put("todayNewMember", todayNewMember);
        map.put("totalMember", totalMember);
        map.put("thisWeekNewMember", thisWeekNewMember);
        map.put("thisMonthNewMember", thisMonthNewMember);
        map.put("todayOrderNumber", todayOrderNumber);
        map.put("thisWeekOrderNumber", thisWeekOrderNumber);
        map.put("thisMonthOrderNumber", thisMonthOrderNumber);
        map.put("todayVisitsNumber", todayVisitsNumber);
        map.put("thisWeekVisitsNumber", thisWeekVisitsNumber);
        map.put("thisMonthVisitsNumber", thisMonthVisitsNumber);
        map.put("hotSetmeal", hotSetmeal);
        return map;
    }
}

